<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>_props的简写方式</title>
</head>
<body>
  <div id="test"></div>
  <div id="test1"></div>
  <div id="test2"></div>

  <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
  <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
  <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
  <script src="https://cdn.staticfile.org/prop-types/15.6.1/prop-types.js"></script>
  

  <script type="text/babel">
    class Person extends React.Component {
      // props的简写：用static  就可以把属性写在类里面
      static propTypes = {
        name: PropTypes.string.isRequired,
        sex: PropTypes.string,
        age: PropTypes.number,
        speak: PropTypes.func
      }
      static defaultProps = {
        sex: 'boy',
        age: 19
      }
      render () {
        const { name, sex, age } = this.props
        return (
          <ul>
            <li>姓名: { name }</li>  
            <li>性别: { sex }</li>  
            <li>年龄: { age }</li>  
            {speak()}
          </ul>
        )
      }
    }

    function speak() {
      return '说话'
    }

    ReactDOM.render(<Person name="tom" speak={speak} />, document.getElementById('test'))
  </script>
</body>
</html>